package com.library.service;

import com.library.dao.BooksMapper;
import com.library.entity.Books;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/13.
 */
@Service("BooksService")
public class BooksServiceImpl implements BooksService {

    @Autowired
    private BooksMapper booksMapper;

    @Override
    public List<Books> search(String bookName) {
        Map<String,Object> params = new HashMap<>();
        if (bookName != null && !bookName.equals("")){
            params.put("name","%"+bookName+"%");
        }
        return booksMapper.findBooks(params);
    }

    @Override
    public List<Books> filter(String type) {
        return booksMapper.findBooksBytype(type);
    }

    @Override
    public List<Books> allBooks(int pageOffset) {
        Map<String,Object> params = new HashMap<>();
        params.put("pageOffset",pageOffset*10);
        params.put("pageSize",10);
        return booksMapper.allBooks(params);
    }

    @Override
    public List<Books> pageSize() {
        return booksMapper.pageSize();
    }

    @Override
    public Books findById(int id) {
        return booksMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateBooks(Books books) {
        booksMapper.updateByPrimaryKey(books);
    }
}
